//
//  WEXWelcomeViewController.m
//  microBlog_oc
//
//  Created by apple on 16/4/23.
//  Copyright © 2016年 Hill. All rights reserved.
//

//define this constant if you want to use Masonry without the 'mas_' prefix
#define MAS_SHORTHAND

//define this constant if you want to enable auto-boxing for default syntax
#define MAS_SHORTHAND_GLOBALS

#import <Masonry/Masonry.h>
#import <SDWebImage/UIImageView+WebCache.h>

#import "WEXWelcomeViewController.h"
#import "UILabel+WEXExtension.h"

#import "WEXUserAccountViewModel.h"

@interface WEXWelcomeViewController ()

@property (nonatomic, strong) UIImageView *igv_headView;

@property (nonatomic, strong) UILabel *lb_message;

@end

@implementation WEXWelcomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self setupUI];
}


# pragma mark -
# pragma mark 动画效果
- (void)viewDidAppear:(BOOL)animated{
    
    [super viewDidAppear:animated];
    
    [self.igv_headView updateConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(100);
        
    }];
    
    [UIView animateWithDuration:1 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:0 options:0 animations:^{
        
        [self.view layoutIfNeeded];
        
    } completion:^(BOOL finished) {
        
        [UIView animateWithDuration:1 animations:^{
            
            self.lb_message.alpha = 1;
            
        } completion:^(BOOL finished) {

            
            [[NSNotificationCenter defaultCenter] postNotificationName:WEXChangeRootVCNotification object:self];
        }];
    }];
    
}




# pragma mark -
# pragma mark 初始化界面
- (void)setupUI {
    
    //    设置背景颜色
    self.view.backgroundColor = [UIColor colorWithWhite:180 / 255.0 alpha:1];
    
    //    添加用户头像
    UIImageView *igv_headView = [[UIImageView alloc] init];
    
    self.igv_headView = igv_headView;
    
    igv_headView.image = [UIImage imageNamed:@"avatar_default_big"];
    igv_headView.layer.cornerRadius = 40;
    igv_headView.layer.masksToBounds = true;
    
    
    
    NSString *urlString = [WEXUserAccountViewModel sharedViewMoel].account.avatar_large;
    
    NSURL *url = [NSURL URLWithString:urlString];
    
    [igv_headView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"avatar_default_big"]];
    
    [self.view addSubview:igv_headView];
    
    //    添加用户头像的约束
    [igv_headView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.size.equalTo(CGSizeMake(80, 80));
        make.centerX.equalTo(self.view);
        make.top.equalTo(200);
        
    }];
    
    //    添加欢迎信息
    UILabel *lb_message = [[UILabel alloc] initWithTextColor:[UIColor darkGrayColor] withFontSize:15];
    lb_message.text = @"欢迎回来";
    self.lb_message = lb_message;
    [self.view addSubview:lb_message];
    
    //    添加欢迎信息的约束
    [lb_message mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self.view);
        make.top.equalTo(igv_headView.mas_bottom).offset(20);
        
    }];
    
    
}




@end
